//
//  MainTabbarController.m
//  oc微博
//
//  Created by 代亚洲 on 16/4/18.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "MainTabbarController.h"
#import "HomeController.h"
#import "MessageController.h"
#import "DiscoberController.h"
#import "MEController.h"

#import "Maintabbar.h"


@interface MainTabbarController ()

@end

@implementation MainTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    [self addChildViewController:HomeController];
    
    
    HomeController *hc=[[HomeController alloc]init];
    [self addChildViewController:hc title:@"主页" imageName:@"tabbar_home"];
    
    MessageController *mc =[[MessageController alloc]init];
    [self addChildViewController:mc title:@"消息" imageName:@"tabbar_message_center"];
    
    DiscoberController *dc =[[DiscoberController alloc]init];
    [self addChildViewController:dc title:@"搜索" imageName:@"tabbar_discover"];
    
    MEController *mec = [[MEController alloc]init];
    [self addChildViewController:mec title:@"我" imageName:@"tabbar_profile"];
    // 只读属性，直接设置行不通
    // 如果系统的一些只读属性，私有属性，不能直接设置值的话。就可以使用 kvc 去设置
    // kvc的底层是运行时 runtime
    Maintabbar *tabBar = [[Maintabbar alloc]init];
    
    [self setValue:tabBar forKey:@"tabBar"];
}

-(void)addChildViewController:(UIViewController *)vc title:(NSString *)title imageName:(NSString *)imageName{

    vc.title =title;
    vc.tabBarItem.image=[UIImage imageNamed:imageName];
//    设置图片渲染模式为默认模式
    NSString *str= [NSString stringWithFormat:@"%@_selected",imageName];
    vc.tabBarItem.selectedImage= [[UIImage imageNamed:str]
    imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    设置文本选中时颜色
     NSDictionary *nary=@{NSForegroundColorAttributeName:[UIColor orangeColor]};
    [vc.tabBarItem setTitleTextAttributes:nary forState:UIControlStateSelected];
    //        设置传进来的控制器为导航控制器的主控制器
    
    [self addChildViewController:[[UINavigationController alloc]initWithRootViewController:vc]];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
